package com.orafl.use.comorafluse.IOC.Lookup;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Map;


/**
 * 依赖查找
 */
public class DependcyLookupDemo {

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(LookUpBean.class,ObjectFactoryTest.class);
        //context.scan();
        // bean名称查找
        LookUpBean bean = (LookUpBean) context.getBeanFactory().getBean("lookUpBean");
        System.out.println("-************************" + bean.toString());
        //类型查找
        LookUpBean typeFindBean = (LookUpBean) context.getBeanFactory().getBean(LookUpBean.class);
        Map<String, LookUpBean> map = context.getDefaultListableBeanFactory().getBeansOfType(LookUpBean.class);

        //通过 间接获取
        ObjectFactory factory =(ObjectFactory) context.getBeanFactory().getBean("ObjectFactoryTest");
        LookUpBean beanLazy = (LookUpBean) factory.getObject();

        context.close();

    }
}
